<template>
  <el-card class="content">
    <el-row>
      <el-col :span="4">
        <span>事故点：</span>
        <el-input
          placeholder="请输入巡查点"
          size="mini"
          style="width: 200px"
          v-model="query.inspectionPoint"
          clearable
        ></el-input>
      </el-col>
      <el-col :span="9">
        <span>开始时间：</span>
        <el-date-picker
          type="datetime"
          placeholder="选择开始日期"
          default-time="00:00:00"
          size="mini"
          v-model="startTime"
          :picker-options="pickerOptions0"
          clearable
        ></el-date-picker>
        <span>结束时间：</span>
        <el-date-picker
          type="datetime"
          placeholder="选择结束日期"
          default-time="00:00:00"
          size="mini"
          v-model="endTime"
          :picker-options="pickerOptions0"
          clearable
        ></el-date-picker>
      </el-col>
      <el-col :span="5">
        <el-button
          class="black-button"
          size="mini"
          type="primary"
          @click="getSearch"
          >查询</el-button
        >
      </el-col>
    </el-row>
    <el-table
      :data="accidentReportList"
      stripe
      size="small"
      :header-cell-style="{ 'text-align': 'center' }"
      :cell-style="{ 'text-align': 'center' }"
      class="el-table-box"
    >
      <el-table-column
        prop="inspectionPoint"
        label="事故点"
        align="center"
        width="150px"
      >
      </el-table-column>
      <el-table-column
        prop="reportTime"
        label="巡查日期"
        align="center"
      ></el-table-column>

      <el-table-column
        prop="reportUserName"
        label="巡查人"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="accidentTypeName"
        label="事故类型"
        align="center"
      ></el-table-column>
      <el-table-column
        prop="accidentContent"
        label="事故内容"
        align="center"
      ></el-table-column>
    </el-table>
    <el-row type="flex" justify="end">
      <el-pagination
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
        :current-page="query.page"
        :page-sizes="[10, 15]"
        :page-size="query.pagesize"
        layout="total, sizes, prev, pager, next, jumper"
        :total="total"
      >
      </el-pagination>
    </el-row>
  </el-card>
</template>
<script>
import {
  getAccidentReportByPage,
  getTailingPondList,
} from "../../../api/safety-management-api";
import moment from "moment";

export default {
  name: "AccidentReportBody",
  props: {
    node: Object,
    require: true,
  },
  data() {
    return {
      endTime: moment().format("YYYY-MM-DD HH:mm:ss"),
      startTime: moment().subtract(1, "months").format("YYYY-MM-DD 00:00:00"),
      pickerOptions0: {
        disabledDate(time) {
          return time.getTime() > Date.now(); //如果没有后面的-8.64e6就是不可以选择今天的
        },
      },
      query: {
        page: 1,
        pagesize: 10,
        inspectionPoint: null,
      },
      total: null,
      // 存放所有交接班信息列表数据
      accidentReportList: [],
      tailingPondId: "",
    };
  },
  created() {
    this.getTailingPondList();
  },
  methods: {
    //查询尾矿库列表
    async getTailingPondList() {
      const res = await getTailingPondList({
        unitId: sessionStorage.getItem("unitId"),
      });
      this.tailingPondId = res.parameter[0].id;
      this.getAccidentReportList();
    },
    async getAccidentReportList() {
      console.log(this.tailingPondId);
      const res = await getAccidentReportByPage({
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        tailingPondId: this.tailingPondId,
      });
      if (res.resultCode == "200") {
        this.accidentReportList = res.parameter.list;
        this.total = res.parameter.total;
      } else {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.accidentReportList = [];
      }
    },
    async getSearch() {
      let queryData = {
        startTime: moment(this.startTime).format("YYYY-MM-DD 00:00:00"),
        endTime: moment(this.endTime).format("YYYY-MM-DD HH:mm:ss"),
        timeType: this.timeType,
      };
      const res = await getAccidentReportByPage({
        startTime: queryData.startTime,
        endTime: queryData.endTime,
        pageCount: this.query.page,
        pageSize: this.query.pagesize,
        inspectionPoint: this.query.inspectionPoint,
        tailingPondId: this.tailingPondId,
      });
      if (res.resultCode == "200") {
        console.log(res);
        this.$message({
          type: "success",
          message: "成功查询到数据",
          offset: 400,
          duration: 1000,
        });
        this.accidentReportList = res.parameter.list;
        this.total = res.parameter.total;
      } else {
        this.$message({
          message: "暂无数据",
          offset: 400,
          duration: 1000,
        });
        this.accidentReportList = [];
      }
    },
    // 监听 pagesize 改变的事件
    handleSizeChange(val) {
      this.query.pagesize = val;
      this.getAccidentReportList();
    },
    // 监听 页码值 改变的事件
    handleCurrentChange(val) {
      this.query.page = val;
      this.getAccidentReportList();
    },
  },
};
</script>

<style scoped>
.content {
  margin-right: 5px;
  height: 87vh;
}
.list {
  height: 83vh;
}
.el-table {
  margin-bottom: 20px;
  margin-top: 20px;
  display: block;
  height: 73vh;
  overflow-y: auto;
}
.el-table::before {
  z-index: inherit;
}
table {
  text-align: center;
}
</style>